//
//  AdViewManager.m
//  BaoVn
//
//  Created by Phuong Le on 5/17/15.
//  Copyright (c) 2015 Le Anh Tai. All rights reserved.
//

#import "AdViewManager.h"
#import "WebsiteViewController.h"
#import "AdGADBanner.h"
#import "AdiAdBanner.h"

@implementation AdViewManager
static AdViewManager *_shared;

+ (AdViewManager *)shared
{
    if (_shared == nil)
    {
        _shared = [[AdViewManager alloc] init];
    }
    
    return _shared;
}

- (instancetype)init
{
    if (self = [super init])
    {
        _currAdView = nil;
        _currWebsiteViewController = nil;
    }
    
    return self;
}

- (void)setupHeightForAdView
{
    if ([_currAdView isKindOfClass:[ADBannerView class]])
    {
        if (Is_Landscape)
        {
            [(ADBannerView *)_currAdView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierLandscape];
        }
        else
        {
            [(ADBannerView *)_currAdView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifierPortrait];
        }
    }
    else if ([_currAdView isKindOfClass:[GADBannerView class]])
    {
        if (Is_Landscape)
        {
            [(GADBannerView *)_currAdView setAdSize:kGADAdSizeSmartBannerLandscape];
        }
        else
        {
            [(GADBannerView *)_currAdView setAdSize:kGADAdSizeSmartBannerPortrait];
        }
    }
}

- (void)attachAdView
{
    if (_currAdView == nil || _currWebsiteViewController == nil)
    {
        return;
    }
    
    [_currWebsiteViewController attachAdView:_currAdView];
}

- (void)detachAdView
{
    if (_currAdView)
    {
        [_currAdView removeFromSuperview];
    }
}
@end
